package com.linxiao.payment.web.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.linxiao.payment.core.constants.IfCodeEnum;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.linxiao.payment.web.mapper.PayInterfaceConfigMapper;
import com.linxiao.payment.web.domain.PayInterfaceConfig;
import com.linxiao.payment.web.service.IPayInterfaceConfigService;

/**
 * 支付接口配置参数Service业务层处理
 *
 * @author ruoyi
 * @date 2024-01-25
 */
@Service
public class PayInterfaceConfigServiceImpl implements IPayInterfaceConfigService {
    @Autowired
    private PayInterfaceConfigMapper payInterfaceConfigMapper;

    /**
     * 查询支付接口配置参数
     *
     * @param id 支付接口配置参数主键
     * @return 支付接口配置参数
     */
    @Override
    public PayInterfaceConfig selectPayInterfaceConfigById(Long id) {
        return payInterfaceConfigMapper.selectPayInterfaceConfigById(id);
    }

    /**
     * 查询支付接口配置参数列表
     *
     * @param payInterfaceConfig 支付接口配置参数
     * @return 支付接口配置参数
     */
    @Override
    public List<PayInterfaceConfig> selectPayInterfaceConfigList(PayInterfaceConfig payInterfaceConfig) {
        return payInterfaceConfigMapper.selectPayInterfaceConfigList(payInterfaceConfig);
    }

    /**
     * 新增支付接口配置参数
     *
     * @param payInterfaceConfig 支付接口配置参数
     * @return 结果
     */
    @Override
    public int insertPayInterfaceConfig(PayInterfaceConfig payInterfaceConfig) {
        payInterfaceConfig.setCreateTime(DateUtils.getNowDate());
        return payInterfaceConfigMapper.insertPayInterfaceConfig(payInterfaceConfig);
    }

    /**
     * 修改支付接口配置参数
     *
     * @param payInterfaceConfig 支付接口配置参数
     * @return 结果
     */
    @Override
    public int updatePayInterfaceConfig(PayInterfaceConfig payInterfaceConfig) {
        payInterfaceConfig.setUpdateTime(DateUtils.getNowDate());
        return payInterfaceConfigMapper.updatePayInterfaceConfig(payInterfaceConfig);
    }

    /**
     * 批量删除支付接口配置参数
     *
     * @param ids 需要删除的支付接口配置参数主键
     * @return 结果
     */
    @Override
    public int deletePayInterfaceConfigByIds(Long[] ids) {
        return payInterfaceConfigMapper.deletePayInterfaceConfigByIds(ids);
    }

    /**
     * 删除支付接口配置参数信息
     *
     * @param id 支付接口配置参数主键
     * @return 结果
     */
    @Override
    public int deletePayInterfaceConfigById(Long id) {
        return payInterfaceConfigMapper.deletePayInterfaceConfigById(id);
    }

    /**
     *
     * @param mchId
     * @param ifCodeEnum
     * @return
     */
    @Override
    public PayInterfaceConfig selectByMchIdAndIfCode(long mchId, IfCodeEnum ifCodeEnum) {
        PayInterfaceConfig query = new PayInterfaceConfig();
        query.setMchId(mchId);
        query.setIfCode(ifCodeEnum.getInsCode());
        List<PayInterfaceConfig> payInterfaceConfigs = payInterfaceConfigMapper.selectPayInterfaceConfigList(query);
        if (CollUtil.isNotEmpty(payInterfaceConfigs)) {
            return payInterfaceConfigs.get(0);
        }
        return null;
    }
}
